<?php

use think\migration\Migrator;
use think\migration\db\Column;

class FixDataCouponOrderzeorOrder extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        // 修复 profit 金额为0 的订单为待结算的 历史数据

        \app\model\CouponOrder::query()
            ->where('profit' ,0)
            ->where('status',3)
            ->where('agent_settle_status',1)
//            ->where('settled_at','<',date('Y-m-d H:i:s'))
            ->select()->each(function (\app\model\CouponOrder $couponOrder){
//                $couponOrder->log .= date('Y-m-d H:i:s') . '手动修改 佣金0 迟迟没有结算，改为待结算';
                $couponOrder->agent_settle_status = \app\model\CouponOrder::C_AGENT_SETTLE_STATUS_WAIT;
                $couponOrder->save();
            });

    }
}
